package 笔试;

public class 鸡兔同笼 {
    public int[] chickenAndRabbits (int heads, int feet) {
        // write code here
        int[] res = new int[2];

        int x = 0;
        int y = 0;

        for(int i = 1; i <= heads; i++) {
            int j = heads-i;
            x = 2 * i;
            y = 4 * j;
            if(x + y == feet) {
                res[0] = i;
                res[1] = j;
                break;
            }
        }

        if(res[0] == 0 && res[1] == 0) {
            return new int[] {-1,-1};
        }
        return res;
    }
}
